<!--
 * @Author: Zhouxin 2890091630@qq.com
 * @Date: 2024-08-26 23:50:05
 * @LastEditors: Zhouxin 2890091630@qq.com
 * @LastEditTime: 2024-08-27 00:02:23
 * @FilePath: \2024-8-22(26)-day13\object.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> 3+1种 对象创建(生产) 方式</title>
</head>
<body>
    <script>
        //字面量对象
        var myMessage = {
            name:"zhou",
            sex:"man",
            age:21,
            study:function(){
                console.log("好好学习，天天向上！");
            }
        }

        //原生对象实例化New Object()
        var myMessage = new object();
        myMessage.name="zhou";
        myMessage.sex="man";
        myMessage.age="21";
        myMessage.study = function(){
            console.log("好好学习，天天向上！");
        }

        //工厂函数创建对象
        function creatCat(name,age,color){
            var cat = new object();
            cat.name = name;
            cat.age = age;
            cat.color = color;
            cat.favorite = "虾肉";
            cat.speak = function(){
                console.log("喵喵喵~");
            }
            return cat;
        }

        var myCat = createCat("咪咪",1,"grey")

        //自定义构造函数

        function Cat(name,age,color,favorite){
            this.name = name;
            this.age = age;
            this.color = color;
            this.favorite = favorite;
            this.speak = function(){
                console.log("喵喵喵~");
            }
        }
        var myCat = new Cat("咪咪",1,"grey","虾肉")

    </script>
</body>
</html>